import pandas as pd
from seeting import *
from numpy import NaN

class Data:
    def __init__(self):
        # self.get_con = CONNECT
        self.get_con = CONNECTRDATA
        self.eng = ENGINE
        self.data_con = CONNECTDATA

    def get_raw_data(self):
        try:
            # data_raw = pd.read_sql('select * from store', con=self.get_con)
            data_raw = pd.read_sql('select STORE_NAME, STORE_CITY, STORE_CODE, LONGITUDE, LATITUDE from [dbo].[OC_CENTER_T_STORE] with(nolock)', con=self.get_con)
            return data_raw
        except MySQLdb.Error as e:
            print('Error: %s' % e)
        finally:
            self.get_con.close()


    def send_data(self, dataset):
        try:
            # dataset.to_sql('test4', con=self.eng, if_exists='replace', index=False)
            self.eng.raw_connection()
            dataset.to_sql('test2', con=self.eng,if_exists='replace',index=False)
        except MySQLdb.Error as e:
            print('Error: %s' % e)


    def get_data(self):
        dataset = pd.read_sql('select * from test2',con=self.data_con)
        return pd.DataFrame(dataset).dropna()
#
# data = Data()
# raw_data = data.get_raw_data()
# data.send_data(raw_data)
# dataset = data.get_data()
# print(dataset.head(10))

